package com.project.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.bean.SuppliersBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 供货商mapper接口
 */
@Mapper
public interface ISuppliersMapper extends BaseMapper<SuppliersBean> {


    /**
     * 模糊查询，根据供货商名称，经营范围，查询供货商对象，
     * 得到供货商名称，负责人，经营范围，并分页
     * @param suppliersName     供货商名称
     * @param suppliersRange    经营范围
     * @return                  供货商对象
     */
    public List<SuppliersBean> findByItem(@Param("suppliersName") String suppliersName,@Param("supplierRange") String suppliersRange);


    /**
     * 按id查询供货商信息详情
     * @param id    id
     * @return      供货商对象
     */
    @Select("select * from sys_suppliers where pk_suppliersId=#{id}")
    @ResultMap("supplierMap")
    public SuppliersBean findById(int id);


    /***
     * 添加供货商信息
     * @param suppliers
     */
    @Insert("INSERT INTO sys_suppliers(suppliersName,supplierManager,supplierPhone,supplierAddress,supplierRange)" +
            "VALUES(#{suppliersName},#{supplierManager},#{supplierPhone},#{supplierAddress},#{supplierRange})")
    public void addSuppliers(SuppliersBean suppliers);


    /**
     * 按id修改供货商信息
     * 修改负责人姓名，电话
     * @param id                    id
     * @param suppliersManager      负责人
     * @param suppliersPhone        负责人电话
     */
    @Update("update sys_suppliers set supplierManager=#{suppliersManager} , supplierPhone=#{suppliersPhone} where pk_suppliersId=#{id}")
    public void updateSuppliers(@Param("id") int id,@Param("suppliersManager") String suppliersManager,@Param("suppliersPhone")String suppliersPhone);


    @Select("select * from sys_suppliers")
    @ResultMap("supplierMap")
    public List<SuppliersBean> findAll();
}
